package fr.pud.client.controller.fleet;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import fr.pud.client.i18n.LanguagesConstants;
import fr.pud.client.images.ImagesDatabase;
import fr.pud.client.model.Fleet;
import fr.pud.client.view.AddVehicleFrame;

/**
 * The controller to remove a vehicle selected from the fleet.
 * 3 avr. 2012 - Projet_Ose
 * @author Simon Devineau, Adrien Hierry, Leopold Houdin, Pierre Reliquet
 *         Ecole des Mines de Nantes
 *         DeleteVehicleFromFleet.java
 */
public class DeleteVehicleFromFleet extends AbstractAction {
    /**
     * The serial UID
     */
    private static final long serialVersionUID = 4431810392321660957L;

    /**
     * Default constructor
     */
    public DeleteVehicleFromFleet() {
        this.putValue(NAME, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.DELETE_VEHICLE));
        this.putValue(SHORT_DESCRIPTION, LanguagesConstants.LANGUAGE
                .getString(LanguagesConstants.DELETE_VEHICLE));
        this.putValue(SMALL_ICON, ImagesDatabase.FULL_TRASH);
    }

    /**
     * Removes the selected item.
     */
    /*
     * (non-Javadoc)
     * @see
     * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    @Override
    public void actionPerformed(ActionEvent aArg0) {
        int toDelete = AddVehicleFrame.getInstance().getFleetInformation()
                .getSelectedIndex();
        Fleet.getInstance().remove(toDelete);
        if (Fleet.getInstance().getVehicles().size() == 0) {
            AddVehicleFrame.getInstance().getModify().setVisible(false);
            AddVehicleFrame.getInstance().getDelete().setVisible(false);
        }
        else {
            AddVehicleFrame.getInstance().getModify().setVisible(true);
            AddVehicleFrame.getInstance().getDelete().setVisible(true);
        }
    }
}
